(function()
{
	var tableFun = function(options)
	{
		this.id = getRandId();
		this.data = null;
		this.data0 = [];
		this.rows = 0;
		this.html = '';
		this.page = 0;
		this.pagesize = 0;
		this.allpage = 1;
		this.opFuntionList = [];
		this.searchPara = null;
		// 停止加载数据
		this.stopSetData = false;
		// 需要加载数据，stopSetData为真，程序却来调用是，该值就为真
		this.needSetData = false;
		this.mulist = {};
		// 根据顶部命令生成的代码
		this.tophtml = '';
		this.thisrowdetail = false;
		if (options)
		{
			// 以下为初始化例子
			this.options = $.extend({
				// 标题
				caption : '',
				// 容器,主容器为 maincontent
				container : '',
				// 默认为空，detail 表示为详情展示, tablelist 为选择 , heightfree 不限制（固定）行高
				classname : '',
				// 指定页大小，如果指定，则不需要最小高度
				pagesize : 0,
				// 自动刷新时间，单位毫秒
				autorefresh : 0,
				// table 或者为list，list模式则只能列表单项，前面可以加图标,但不支持多选
				listmodel : '',
				// list模式的ul宽度
				listulwidth : 0,
				// 表示比计算的页高度再增加一些（一般为负数，可以为下面多留些空间)
				height : 0,
				// 原有的基础上添加页大小
				addpagesize : 0,
				// 显示头部
				showheader : true,
				// 溢出动作，auto scroll 默认为隐藏
				overflow : '',
				// 显示业
				showpage : false,
				// 是否具有刷新按钮顶部命令,格式：{cmd1:{caption:'',icon:'',fun(){},cmd2: ... }
				refreshbtn : true,
				// 顶部命令定义
				tophtml : null,
				// 没有数据时显示的代码
				noDataHtml : '',
				// 顶部文本
				tophelphtml : null,
				// 底部文本 点击确定需要执行的函数 , 可以直接是函数，也可以是一个数组 [ {'cap':'ok','fun': function(){}} , ]
				bottomhelphtml : null,
				// 点击确定执行的函数
				okFun : null,
				// function(index, idi, data){}, // 行点击函数，如未定义则执行第一个操作按钮 右键菜单（与_op_叠加），[{},,] , 与 _op_ 格式一样，该值为false时表示不显示右键菜单，默认为空数组
				clickTrFun : null,
				// 右键菜单
				rightMenu : [],
				// 是否关闭 _op_ 菜单（但显示快捷键），关闭后 多选和右键依旧有效(不指定为true或false将为当前默认)
				hideop : null,
				// 是否关闭 _op_ 菜单（不显示快捷键），关闭后 多选和右键依旧有效(默认为false
				hideoption : false,
				// 调入数据
				loadDataFun : function(page, fun, searchpara)
				{
					// searchpara 为搜索参数 ， 可在任何地方设置 table.setSearchPara({shopId : st});
					// 在调入数据前获取参数，如：if (searchpara) {for ( var na in searchpara)para[na] = searchpara[na]; }
					var d = [ {
						k1 : 'K1Value',
						k2 : 'K2Value'
					}, {
						k1 : 'K1Value',
						k2 : 'K2Value'
					} ];
					var allpage = 50;
					fun(d, allpage);
				},
				header : {
					// 是否显示多选按钮，默认为假
					_mu_ : false,
					// 分别为标题，宽度，数据类型，图标，输入框改变值回调函数 ,是否双击编辑，值转换函数，单击TD响应
					// 宽度如果前面带min，表示最小宽度，如果带max，标识最大宽度，多出的带省略号
					// 双击编辑时将去掉html标签，除非含有“html”这个classname
					k1 : [ 'K1Caption', '23% or 30px', 'date', 'fa-edit', function(index, key, oldvalue, value, inputobj, data)
					{
						// 修改
					}, false, function(data, index)
					{
						// 传值
					}, function(index, idi, data)
					{
						// 单击响应
					} ],
					// 列标题，为空表示隐藏隐藏
					k2 : 'k2Caption',
					// 行操作按钮
					_op_ : [ {
						// 为true时隐藏该操作图标， 或与具体的值相等时也隐藏
						hidden : true,
						title : 'edit',
						icon : 'fa-files-o',
						// 是否在多选按钮中显示，默认为true
						_mu_ : false,
						// 操作前确认信息，为空则表示直接操作
						confirm : '',
						// 关闭右键菜单按钮，一般只出现在多选中（hiderm设置为真，hideop必须设置为真，否则会出错）
						hiderm : false,
						// 本按钮不在表格显示（可以在右键菜单显示)
						hideop : false,
						// 多列操作时是否整体一次性操作(传入处理参数)，还是每个订单分布处理，为真时处理，则调用当前函数的三个参数均为数组
						muonce : false,
						// 右键菜单顶部横线，即分组
						rmtopborder : false,
						fun : function(index, idi, data)
						{
						}
					} ]
				}
			}, options);
			app.templete(this);
			this._setEvent();
			this._setHeader();
		}
	};
	// 根据html对象取得其所在的table对象
	tableFun.prototype.getThis = function(obj)
	{
		if (typeof obj == 'string')
			return app.templete(obj);
		var k = $(obj).parents('.tablebox');
		if (k.length > 0)
		{
			return app.templete(k[0].id);
		}
		return null;
	}
	/**
	 * 取得单行高度，这个与css设置有关，也可以在皮肤中设置重载
	 */
	tableFun.prototype.getTdHeight = function(key)
	{
		return app.vm ? 39 : 36;
	}
	/**
	 * 取得命令行坐标
	 */
	tableFun.prototype.getCmdOffset = function(key)
	{
		var tt = $('.table' + this.id + ' li.' + key);
		if (tt.length == 0)
		{
			var tt = $('#' + this.id + ' .cmdbox .' + key);
		}
		return tt.offset();
	}
	tableFun.prototype.hideCmd = function(key, isHide)
	{
		var k = $('#' + this.id + ' .cmdbox .' + key);
		if (k.length <= 0)
			return;
		if (isHide !== false)
			isHide = true;
		if (isHide)
		{
			if (k.length > 0)
			{
				k.hide();
				k.addClass('hidden');
			}
		}
		else
		{
			if (k.length > 0)
			{
				k.show();
				k.removeClass('hidden');
			}
		}
	}
	/**
	 * 设置命令行标题
	 */
	tableFun.prototype.cmdCaption = function(key, cap)
	{
		if (!this.cmdhtml || !this.options.tophtml || !this.options.tophtml[key])
			return;
		var tt = $('#' + this.id + ' .cmdbox .' + key + ' span.cap');
		if (arguments.length < 2)
			return tt.html();
		var actionremove = false;
		if (!cap || cap == this.options.tophtml[key]['caption'])
		{
			cap = this.options.tophtml[key]['caption'];
			actionremove = true;
		}
		tt.html(cap);
		// 设置颜色
		tt = $('#' + this.id + ' .cmdbox .' + key + ' span');
		if (actionremove)
			tt.removeClass('red');
		else
			tt.addClass('red');
		this.cmdhtml.showMoreLeft();
	}
	/**
	 * 设置搜索词
	 */
	tableFun.prototype.setSearchPara = function(para)
	{
		if (!this.searchPara || !para)
			this.searchPara = {};
		if (para)
		{
			for ( var k in para)
			{
				if (para[k] === null)
					delete this.searchPara[k]
				else
					this.searchPara[k] = para[k];
			}
		}
	}
	/**
	 * 设置哪些行需要选择
	 */
	tableFun.prototype.setChecked = function(indexArr, ta)
	{
		if (!ta)
			ta = this;
		var isall = true;
		$('#' + ta.id).find('.check').each(function()
		{
			var xi = parseInt($(this).attr('i'));
			if (indexArr && indexArr.indexOf(xi) >= 0)
				ta._setChecked(this, true);
			else
			{
				ta._setChecked(this, false);
				isall = false;
			}
		});
		setTimeout(function()
		{
			ta.closeChecks(ta, isall);
		}, 100);
	}
	/**
	 * 关闭全选按钮
	 */
	tableFun.prototype.closeChecks = function(ta, checked)
	{
		if (!ta)
			ta = this;
		checked = !!checked;
		var s = $('#' + ta.id).find('.checks');
		for (var i = 0; i < s.length; i++)
		{
			this._setChecked(s[i], checked);
		}
	}
	/**
	 * 取得页行数
	 */
	tableFun.prototype.getPageSize = function()
	{
		if (this.options.pagesize > 0)
		{
			this.pagesize = this.options.pagesize;
			return this.pagesize;
		}
		var tdHeight = this.getTdHeight(); // td 高度
		if (!this.pageHeight)
		{
			var dh = 66;
			var box = $('#' + this.id + ' #table').parents('.layui-layer-content');
			var box2 = $('#' + this.id + ' #table').parents('.fulllayer');
			if (box.length > 0 && box2.length == 0)
			{
				var height = box[0].offsetHeight - dh - 30;
			}
			else
			{
				var top = 42;
				var k = $('#' + this.id + ' #table');
				if (k.length > 0)
				{
					var off = getOffset(k[0]);
					if (off && off.top !== undefined)
						top = off.top;
				}
				var st = $(document).scrollTop();
				if (st > 50)
					st = 50;
				var height = getWindowHeight() - top - dh + this.options.addpagesize * tdHeight + st;
				this.inFull = true;
			}
			if (height >= 64)
				this.pageHeight = height;
		}
		else
			var height = this.pageHeight;
		var dh = 0;
		if (this.data['_mu_'])
			dh -= 32;
		if (this.options.showheader)
			dh -= 40;
		// 全屏手机端，列表数量多些
		if (this.inFull && app.vm && !this.options.addpagesize)
			height = height * 2;
		this.fixedPageSize = Math.max(2, Math.floor((height + dh) / tdHeight));
		this.pagesize = this.morePageSize ? this.morePageSize : this.fixedPageSize;
		if (this.morePageSize > 0)
			var minh = Math.min(this.morePageSize, this.fixedPageSize) * tdHeight - dh + 14;
		else
			var minh = this.fixedPageSize * tdHeight - dh + 14;
		if (app.vm)
		{
			if (this.pagesize > this.fixedPageSize)
				$('#' + this.id).css('paddingBottom', '50px');
			else
				$('#' + this.id).css('paddingBottom', '0');
		}
		else
			$('#' + this.id + ' #table').css('min-height', minh + 'px');
		return this.pagesize;
	}
	tableFun.prototype.showTd = function(key)
	{
		if (this.data[key])
		{
			if (this.data[key].icon)
			{
				this.data[key].icon = this.data[key].icon.replace(' hidden', ' ');
				this.data[key].icon = this.data[key].icon.replace('hidden ', ' ');
			}
		}
	}
	/**
	 * 设置跨行跨列，调入数据之后设置 hangi==-1 表示标题
	 */
	tableFun.prototype.setSpan = function(hangi, dataName, colSpan, rowSpan, tryi)
	{
		var that = this;
		tryi = tryi || 0;
		if (tryi > 6)
			return;
		if (hangi < 0)
			var t = $('#' + that.id + ' th.th-' + dataName);
		else
			var t = $('#' + that.id + ' tr.i' + hangi + ' td.td-' + dataName);
		if (t.length <= 0)
		{
			setTimeout(function()
			{
				that.setSpan(hangi, dataName, colSpan, rowSpan, tryi + 1);
			}, 10);
			return;
		}
		if (colSpan > 1)
		{
			// 横向
			for (var i = 1; i < colSpan; i++)
				$(t).next().remove();
			t.attr("colSpan", colSpan);
			t.addClass("center");
		}
		if (rowSpan > 1 && hangi >= 0)
		{
			// 纵向
			t.attr("rowSpan", rowSpan);
			for (var i = 1; i < rowSpan; i++)
			{
				$('#' + that.id + ' tr.i' + (hangi + i) + ' td.td-' + dataName).remove();
			}
		}
	}
	tableFun.prototype.hideTd = function(key)
	{
		if (this.data[key])
		{
			if (!this.data[key].icon)
				this.data[key].icon = '';
			this.data[key].icon = ((this.data[key].icon.trim() || '') + ' hidden').trim();
		}
	}
	tableFun.prototype.getData = function(index, key)
	{
		if (arguments.length <= 0)
			return this.data0;
		else if (arguments.length == 1)
			return this.data0[index];
		else if (index >= 0 && index < this.data0.length)
			return this.data0[index][key];
		else
			return undefined;
	}
	tableFun.prototype.addData = function(d, index, replace, justsetData)
	{
		var oldData = this.data0;
		if (arguments.length <= 0)
		{
			if (!justsetData)
				this.setData(oldData);
			return;
		}
		if (d === null && replace)
		{
			if (index >= 0 && index < oldData.length)
			{
				oldData.splice(index, 1);
				if (this.opclass)
					this.opclass.splice(index, 1);
				this.allpage--;
				if (!justsetData)
					this.setData(oldData);
			}
			return;
		}
		if (index < 0)
			index = oldData.length;
		else if (!index)
			index = 0;
		if (!replace)
		{
			if (index >= oldData.length)
			{
				oldData.push(d);
				if (this.opclass)
					this.opclass.push([]);
			}
			else
			{
				oldData.splice(index, 0, d);
				if (this.opclass)
					this.opclass.splice(index, 0, []);
			}
		}
		else if (index >= 0 && index < oldData.length)
		{
			for ( var k in d)
			{
				oldData[index][k] = d[k];
			}
		}
		this.allpage = oldData.length;
		if (!justsetData)
			this.setData(oldData);
	}
	/**
	 * 刷新数据，该操作不仅刷新数据，还会把同级别的其它并列table设置为“需要刷新”
	 */
	tableFun.prototype.refresh = function()
	{
		if (this.tab === null)
		{
			this.setData();
			return;
		}
		this.tab = (new tabFun()).getThis($('#' + this.id));
		if (this.tab)
			this.tab.setNeedRefresh();
		else
			this.tab = null;
		this.setData();
	}
	tableFun.prototype.setData = function(d, page, notclear, tryfindend)
	{
		if (this.stopSetData)
		{
			this.needSetData = true;
			return;
		}
		var that = this;
		this.needSetData = false;
		if (arguments.length < 2 || page < 0 || page == undefined || page == null)
		{
			page = this.page;
		}
		if (!(page > 1))
			page = 1;
		this.page = page;
		if (!this.data)
		{
			// 没有表头数据 ;
			return;
		}
		if ($('#' + this.id).length <= 0)
			return;
		if (!d)
		{
			if (!this.options.loadDataFun)
				return;
			if (!notclear)
				$('#' + this.id + ' #table').css('opacity', '0.5');
			this.options.loadDataFun(page, function(d, allpage, backfun)
			{
				if (!notclear)
					$('#' + that.id + ' #table').css('opacity', '1');
				if (tryfindend > 0 && page > 1 && (!d || d.length == 0))
				{
					tryfindend--;
					that.setData(null, page - 1, true, tryfindend);
					return;
				}
				if (!d)
					return;
				that.page = (!page || page < 1) ? 1 : page;
				that.allpage = allpage;
				app.lockScreen(0, function()
				{
					that.setData(d);
					if (backfun)
					{
						setTimeout(backfun, 100);
					}
				});
			}, this.searchPara || {});
			return;
		}
		if (app.lockScreen())
		{
			app.lockScreen(0, function()
			{
				that.setData(d, page, notclear, tryfindend);
			});
			return;
		}
		if (!notclear)
			$('#' + this.id + ' #table').css('opacity', '1');
		this.rows = d.length;
		var havegetvaluefun = false;
		this.data0 = []; // 原始数据
		var len = d.length;
		for (var i = 0; i < d.length; i++)
		{
			var di = d[i];
			this.data0.push({});
			for ( var k in di)
			{
				if (!this.data[k])
					continue;
				if (this.data[k].data && this.data[k].data.length > len)
					this.data[k].data.length = len;
				this.data0[i][k] = di[k];
				if (this.data[k].getvaluefun)
					continue;
				else if (this.data[k].data)
					this.data[k].data[i] = formatData(di[k], this.data[k]['type']);
			}
		}
		for ( var k in this.data)
		{
			if (this.data[k].getvaluefun)
			{
				for (var i = 0; i < d.length; i++)
					this.data[k].data[i] = formatData(this.data[k].getvaluefun(d[i], i), this.data[k]['type']);
			}
		}
		this._setDataHtml(true);
		this._setPageHtml();
		if (this.options.autorefresh)
		{
			var that = this;
			if (that.autorefresh)
			{
				clearTimeout(that.autorefresh);
			}
			that.autorefresh = setTimeout(function()
			{
				if ($('#' + that.id).length > 0)
					that.setData(null, -1, true);
			}, that.options.autorefresh);
		}
	}
	// 设置操作按钮的class
	tableFun.prototype.setOpClass = function(hangi, i, cla, isRemove)
	{
		if (typeof i == 'object' && i[0] !== undefined)
		{
			for (var ii = 0; ii < i.length; ii++)
			{
				this.setOpClass(hangi, i[ii], cla, isRemove);
			}
			return;
		}
		if (arguments.length == 0 || !this.opclass)
			this.opclass = [];
		if (arguments.length == 1)
		{
			if (!hangi)
				hangi = 0;
			this.opclass[hangi] = [];
		}
		else if (!this.opclass[hangi])
			this.opclass[hangi] = [];
		if (!cla)
		{
			this.opclass[hangi][i] = '';
		}
		else
		{
			cla = (cla + ' ').trim();
			var c = '';
			if (this.opclass[hangi][i])
				c = this.opclass[hangi][i];
			if (isRemove)
			{
				c = (' ' + c + ' ').replace(' ' + cla + ' ', ' ');
			}
			else
			{
				if ((' ' + c + ' ').indexOf(' ' + cla + ' ') < 0)
					c += (c ? ' ' : '') + cla;
			}
			this.opclass[hangi][i] = c.trim();
		}
	}
	tableFun.prototype.hideHelphtml = function(isShow, istop, html)
	{
		if (html)
		{
			if ($('#' + this.id + ' .bottomhelphtml').length <= 0)
				$('#' + this.id).append('<div class="tip bottomhelphtml">' + html + '</div>');
			else
				$('#' + this.id + ' .bottomhelphtml').html(html);
		}
		if (istop !== false && isShow)
			$('#' + this.id + ' .tophelphtml').show();
		if (istop !== false && !isShow)
			$('#' + this.id + ' .tophelphtml').hide();
		if (istop !== true && isShow)
			$('#' + this.id + ' .bottomhelphtml').show();
		if (istop !== true && !isShow)
			$('#' + this.id + ' .bottomhelphtml').hide();
	}
	tableFun.prototype.resetTophtml = function(optionstophtml)
	{
		if (optionstophtml)
		{
			this.options.tophtml = optionstophtml;
		}
		this._gettophtml();
		$('#' + this.id + ' .tophtml').html(this.tophtml);
	}
	/**
	 * 取得key数据数组, 星号表示所有字段，字段前加"!"表示剔除这个字段 s 格式字段 d 原始数据 如果 ，isTwo 为真 ， 则表示为两排，为两排时，必须有name2及value2两个字段（同时可能有key2）
	 */
	tableFun.prototype.getKeyValueArr = function(d, s, isTwo)
	{
		if (!d || d.length <= 0)
			return [];
		var serverName = ajax.getServerName();
		var dd = [];
		var setall = false; // 必须显示所有字段
		var null_value = '!!_!!';
		var havesetname = [];
		var lasti = -1;
		var isOkSetRight = false;
		if (s)
		{
			for (var i = 0; i < s.length; i++)
			{
				var name = s[i];
				var datatype = '';
				if (typeof name != 'string')
				{
					datatype = name[1];
					name = name[0];
				}
				if (name == '*')
				{
					setall = true;
					name = '';
				}
				if (!name)
					continue;
				else
				{
					if (name.indexOf('!') === 0)
					{
						name = name.substring(1);
						d[0][name] = null_value;
					}
					if (d[0][name] === undefined) // 没有值的，赋予空
						d[0][name] = '';
				}
				if (d[0][name] != null_value)
				{
					if (isTwo && isOkSetRight)
					{
						dd[lasti].key2 = name;
						dd[lasti].name2 = name;
						if (typeof datatype == 'function')
							dd[lasti].value2 = datatype(d[0][name], d[0]);
						else
							dd[lasti].value2 = formatData(d[0][name], datatype);
						isOkSetRight = false;
					}
					else
					{
						if (typeof datatype == 'function')
						{
							dd.push({
								key : name,
								name : name,
								value : datatype(d[0][name], d[0]),
							});
						}
						else
						{
							dd.push({
								key : name,
								name : name,
								value : formatData(d[0][name], datatype),
							});
						}
						lasti = dd.length - 1;
						isOkSetRight = true;
					}
					havesetname.push(name);
				}
			}
			if (!setall)
				return dd;
		}
		for ( var name in d[0])
		{
			var v = d[0][name];
			if (v != null_value && havesetname.indexOf(name) < 0)
			{
				var datatype = (name + '|').indexOf('Time|') > 0 ? 'datetime' : '';
				if (isTwo && isOkSetRight)
				{
					dd[lasti].key2 = name;
					dd[lasti].name2 = name;
					dd[lasti].value2 = formatData(v, datatype);
					isOkSetRight = false;
				}
				else
				{
					dd.push({
						key : name,
						name : name,
						value : formatData(v, datatype),
					});
					lasti = dd.length - 1;
					isOkSetRight = true;
				}
			}
		}
		return dd;
	}
	// ////////////////////////////////////////
	//
	// 以下为私有函数
	//
	// /////////////////////////////////////////////////////////
	// 初始化对象，初始化事件
	tableFun.prototype._setEvent = function()
	{
		// 下面只执行一次
		if (tableFun.prototype._)
			return;
		tableFun.prototype._ = 1;
		var that = this;
		// 单机th单元格右边
		$('body').on('click', '.tablebox th', function(e)
		{
			if (e.offsetX <= 24)
			{
				var ta = that.getThis(this);
				ta._clickth(this);
			}
		})
		// 单击单元格（按钮已经被隐藏，弹出右键，屏蔽冒泡)
		$('body').on('click', '.tablebox td.hideop', function(e)
		{
			e = e || event;
			e.stopPropagation();
			var ta = that.getThis(this);
			ta._clickRightMenu(this, e);
		})
		// 双击th单元格
		$('body').on('dblclick', '.tablebox th', function(e)
		{
			if (app.vm)
				return;
			var ta = that.getThis(this);
			ta._clickth(this);
		})
		// 双击td单元格
		$('body').on('dblclick', '.tablebox td', function()
		{
			if (app.vm)
				return;
			var k = $(this).attr('data-key');
			if (!k)
				return;
			var ta = that.getThis(this);
			if (ta && ta.data && ta.data[k] && ta.data[k].dblclickedit && $(this).find('span.dblclickedit').length > 0)
			{
				if ($(this).find('input').length > 0)
					return;
				var isRed = $(this).find('.red').length > 0;
				var v = $(this).find('span').html();
				// 取消相应html代码
				if (!$(this).hasClass('html'))
				{
					v = v.replace(/\n/g, " ");
					v = v.replace(/<\/?.+?>/g, '');
					if (isRed && /^\d{0,10}\.{0,1}\d{0,10}$/.test(v) && v > 0)
						v = 0 - v;
				}
				v = v.replace(/\"/g, "&quot;");
				v = v.replace(/\'/g, "&apos;");
				v = '<input value="' + v + '">';
				$(this).html(v);
				$(this).addClass('input');
				var td = this;
				setTimeout(function()
				{
					var inp = $(td).find('input');
					inp.focus();
					inp.select();
				}, 100);
			}
		});
		// 双击td单元格编辑框失去焦点
		$('body').on('blur', '.tablebox td input', function()
		{
			var k = $(this).parent().attr('data-key');
			var ta = that.getThis(this);
			if (!k || !ta || !ta.data || !ta.data[k].dblclickedit)
				return;
			$(this).parent().removeClass('input');
			$(this).parent().html('<span class="dblclickedit" style="width:100%">' + $(this).val() + '</span>');
		});
		// 点击操作按钮
		$('body').on('click', '.tablebox .op', function(e)
		{
			var index = parseInt($(this).attr('i'));
			if (!config.debug && $(this).hasClass('hui'))
				return;
			if ($(this).hasClass('white'))
				return;
			var xi = $(this).attr('xi');
			var ta = that.getThis(this);
			if (!ta || !ta.data)
				return;
			if (!ta.opFuntionList[xi])
				return;
			e = e || event;
			e.stopPropagation();
			var fun = ta.opFuntionList[xi].fun;
			var confirmMsg = ta.opFuntionList[xi].confirm;
			if (fun)
			{
				var d = [];
				for ( var k in ta.data)
				{
					if (ta.data[k]['data'])
						d[k] = ta.data[k]['data'][index];
				}
				if (confirmMsg)
				{
					var tr = $(this).parents('tr');
					tr.addClass('curhang curhang4');
					confirm(confirmMsg, function()
					{
						fun(index, ta.data[ta.options.keyname].data[index], d, true);
					}, null, false, false, function()
					{
						// 关闭确认框
						tr.removeClass('curhang curhang4');
					});
				}
				else
				{
					var tr = $(this).parents('tr');
					fun(index, ta.data[ta.options.keyname].data[index], d, true);
				}
			}
		})
		// 点总操作按钮
		$('body').on('click', '.tablebox .selectmu .mu', function(e)
		{
			var xi = $(this).attr('xi');
			var ta = that.getThis(this);
			if (!ta || !ta.data)
				return;
			e = e || event;
			e.stopPropagation();
			var fun = ta.opFuntionList[xi].fun;
			var confirmMsg = ta.opFuntionList[xi].confirm;
			var muonce = ta.opFuntionList[xi].muonce;
			if (fun)
			{
				var da = [];
				var unmucheck = false;
				$(this).parents(".tablebox").find('.check').each(function()
				{
					if (this.checked)
					{
						var index = parseInt($(this).attr('i'));
						if (index === 0 || index > 0)
						{
							var ch = $('#' + ta.id + ' #op_' + index + '_' + xi);
							if (ch.length <= 0 || ch.hasClass('hui') || ch.hasClass('hidden'))
							{
								ta._setChecked(this, false);
								unmucheck = true;
								return;
							}
							var a = {};
							for ( var kn in ta.data)
							{
								if (ta.data[kn].data && ta.data[kn].data.length > index)
								{
									a._index = index;
									a._obj = this;
									a[kn] = ta.data[kn].data[index];
								}
							}
							da.push(a);
						}
					}
				});
				if (unmucheck)
				{
					ta.closeChecks(ta);
				}
				if (da.length <= 0)
				{
					errorMsg(app.w('login.msg.NoSelectToOption'));
					return;
				}
				if (confirmMsg)
				{
					confirm(confirmMsg, function()
					{
						dothis(muonce);
					});
				}
				else
				{
					dothis(muonce);
				}
				function dothis(muonce)
				{
					if (!login.isLogin())
					{
						app.doLogin(function()
						{
							dothis(muonce);
						}, true);
						return;
					}
					if (muonce)
					{
						var indexa = [];
						var daa = [];
						var idsa = [];
						for (var curi = 0; curi < da.length; curi++)
						{
							var index = da[curi]._index;
							indexa.push(index);
							daa.push(da[curi]);
							idsa.push(ta.data[ta.options.keyname].data[index]);
						}
						fun(indexa, idsa, daa, true);
						return;
					}
					ta.stopSetData = true;
					var curi = 0;
					var timer = setInterval(function()
					{
						if (curi < da.length)
							loading();
						else
						{
							if (curi == da.length)
							{
								loading(true);
							}
							if (curi == da.length + 2)
							{
								ta.stopSetData = false;
							}
							if (curi > da.length + 20)
							{
								clearInterval(timer);
							}
							if (ta.needSetData)
							{
								ta.setData();
							}
						}
						if (curi < da.length)
						{
							var index = da[curi]._index;
							ta._setChecked(da[curi]._obj, false);
							ta.closeChecks(ta);
							fun(index, ta.data[ta.options.keyname].data[index], da[curi], curi == da.length - 1);
						}
						curi++;
					}, 333);
				}
			}
		})
		// 鼠标按下，记录按下事件
		$('body').on('mousedown', '.tablebox .odd .oddi', function(e)
		{
			// console.log(e);
			var ta = that.getThis(this);
			if (ta)
			{
				ta.mouseDownTimeX = e.clientX;
				ta.mouseDownTime = new Date().getTime();
			}
		})
		// 点击单元格，如果鼠标按下时间超过800ms（即长按响应时间）则取消单击操作，则在试图复杂内容时有用
		$('body').on('click', '.tablebox .odd .oddi', function(e)
		{
			e = e || event;
			var index = parseInt($(this).attr('i'));
			var key = $(this).attr('data-key');
			var ta = that.getThis(this);
			if (!ta || !ta.data)
				return;
			if (ta.mouseDownTime > 0 && (new Date().getTime() - ta.mouseDownTime > 800 || Math.abs(ta.mouseDownTimeX - e.clientX) > 24))
				return;
			if ($(this).find('.dblclickedit').length > 0 || $(this).find('input').length > 0 || $(this).hasClass('tdop'))
				return;
			if (ta.data[key] && ta.data[key].clickfun)
			{
				var d = [];
				for ( var k in ta.data)
				{
					if (ta.data[k]['data'])
						d[k] = ta.data[k]['data'][index];
				}
				e.stopPropagation();
				var re = ta.data[key].clickfun(index, ta.data[ta.options.keyname].data[index], d);
				if (re !== false)
					return;
			}
			// 看行事件
			var thistr = $(this).parent('tr');
			if (ta.options.clickTrFun) // 有行点击函数
			{
				var d = [];
				for ( var k in ta.data)
				{
					if (ta.data[k]['data'])
						d[k] = ta.data[k]['data'][index];
				}
				var re = ta.options.clickTrFun(index, ta.data[ta.options.keyname].data[index], d);
			}
		});
		// 单击右键菜单命令
		$('body').on('click', "ul.tablerightmenu li", function()
		{
			if (window.longpress_havedo >= 3)
				return;
			var i = parseInt($(this).attr('datai'));
			var id = ($(this).parents('ul').attr('id'));
			if (!id || id.indexOf('table') !== 0)
				return;
			var ta = that.getThis(id.substring(5));
			if (ta)
			{
				if (ta.rightMenuRm && ta.rightMenuRm.length > i && ta.rightMenuData)
				{
					var fun = ta.rightMenuRm[i].fun;
					var confirmMsg = ta.rightMenuRm[i].confirm;
					if (fun)
					{
						if (confirmMsg)
						{
							confirm(confirmMsg, function()
							{
								fun(ta.rightMenuData[0], ta.rightMenuData[1], ta.rightMenuData[2]);
							});
						}
						else
							fun(ta.rightMenuData[0], ta.rightMenuData[1], ta.rightMenuData[2]);
					}
				}
				layer.close(tableFun.rightMenulayerIndex);
			}
		})
		// 右键菜单（行）
		$('body').on('mouseup', '.tablebox .odd', function(e)
		{
			e = e || event;
			if (e.button == 2 && $(this).parents('.allowrightmenu').length == 0 && !$(this).hasClass('th') && $(this).parents('.thisrowdetail').length == 0)
			{
				if ($(this).find('.allowrightmenu').length == 0)
				{
					var ta = that.getThis(this);
					ta._clickRightMenu(this, e);
				}
			}
		})
		// 输入框
		$('body').on('change', '.tablebox td.input input', function()
		{
			var index = parseInt($(this).parent().attr('i'));
			var datakey = $(this).parent().attr('data-key');
			var ta = that.getThis(this);
			if (!ta || !ta.data)
				return;
			var fun = ta.data[datakey].inputfun;
			if (fun)
			{
				var d = [];
				for ( var k in ta.data)
				{
					if (ta.data[k]['data'])
						d[k] = ta.data[k]['data'][index];
				}
				var oldvalue = ta.data[datakey].data[index];
				var re = fun(index, datakey, oldvalue, this.value, this, d);
				if (re === false)
				{
					this.value = oldvalue;
				}
				else if (this.value !== oldvalue)
				{
					$(this).parent().addClass('edited');
				}
			}
		});
		// 多选按钮
		$('body').on('click', '.tablebox .checks', function(e)
		{
			e = e || event;
			e.stopPropagation();
			var ta = that.getThis(this);
			var s = this.checked;
			$(this).parents(".tablebox").find('.check').each(function()
			{
				ta._setChecked(this, s);
			});
			var h = $(this).parents(".tablebox").find('.checks');
			for (var i = 0; i < h.length; i++)
			{
				ta._setChecked(h[i], s);
			}
		})
		// 选单个
		$('body').on('click', '.tablebox .check', function(e)
		{
			e = e || event;
			e.stopPropagation();
			var ta = that.getThis(this);
			ta.closeChecks(ta);
			ta._setChecked(this, this.checked);
		})
		// 阻止选框执行行点击
		$('body').on('click', '.thtdmu', function(e)
		{
			e = e || event;
			e.stopPropagation();
		})
		// 页操作事件
		$('body').on('click', '.tablebox .pagestr li a', function()
		{
			if ($(this).parent().hasClass('disabled'))
				return;
			var ta = that.getThis(this);
			if (!ta)
				return;
			var page = parseInt($(this).attr('page'));
			var tryfindend = $(this).attr('tryfindend') == 'yes' ? 4 : 0;
			if (page > 0)
			{
				ta.setData(null, page, false, tryfindend);
				ta.page = page;
			}
			else if (page == -100)
			{
				if (ta.morePageSize)
				{
					ta.morePageSize = false;
					ta.setData(null, 1);
				}
				else
				{
					ta.allpage = 1;
					ta.morePageSize = config.morePageSize > 0 ? config.morePageSize : 300;
					ta.setData(null, 1);
				}
			}
			else if (page <= -1000)
			{
				var i = 0 - page - 1000;
				var ta = that.getThis(this);
				if (ta.options._okFun && ta.options._okFun[i])
					ta.options._okFun[i].fun(ta);
			}
		});
	};
	/**
	 * 设置行选择
	 */
	tableFun.prototype._setChecked = function(obj, s)
	{
		if (obj)
		{
			obj.checked = s;
			if (s)
				$(obj).parents('tr').addClass('curhang curhang3');
			else
				$(obj).parents('tr').removeClass('curhang curhang3');
		}
	}
	/**
	 * 展开单元格，让所有信息都显示
	 */
	tableFun.prototype._explodeTd = function()
	{
		if ($('#' + this.id).find('td').hasClass('max'))
			$('#' + this.id).find('td').removeClass('max');
		else
			$('#' + this.id).find('td').addClass('max');
	}
	/**
	 * 单击行事件
	 */
	tableFun.prototype._clickth = function(obj)
	{
		if ($(obj).hasClass('thtdmu'))
			return;
		if ($(obj).hasClass('thop'))
		{
			var hide = !$(obj).hasClass('hideop');
			app.hideTableOption(hide);
			var ta = this.getThis(obj);
			if (ta)
				ta.options.hideop = hide ? 1 : 0;
		}
		else if ($(obj).hasClass('max'))
		{
			$(obj).removeClass('max');
		}
		else
		{
			$(obj).parents().find('th').removeClass('max');
			$(obj).addClass('max');
		}
		$(obj).parents('table').find('td').removeClass('max');
	}
	tableFun.prototype.showRightMenu = function(obj, e)
	{
		if (e)
			this._clickRightMenu(obj, e);
	}
	/**
	 * 右键处理
	 */
	tableFun.prototype._clickRightMenu = function(obj, e, x0, y0)
	{
		var ta = this.getThis(obj);
		if (!ta || !ta.data || ta.options.rightMenu === false)
			return;
		var iu = $(obj).attr('i');
		if (iu === '' || iu === undefined)
			iu = $(obj).parents('tr').attr('i');
		var index = parseInt(iu);
		var rightMenu = ta.options.rightMenu;
		if (!rightMenu)
			rightMenu = [];
		var op = ta.options.header['_op_'];
		if (!op)
			op = [];
		var rm = [];
		var opclass = [];
		if (ta.opclass && ta.opclass.length > index)
		{
			opclass = ta.opclass[index];
		}
		var rmtopborder2 = false;
		for (var i = 0; i < op.length; i++)
		{
			if (!op[i])
				continue;
			var cla = opclass ? opclass[i] : '';
			if (op[i].hidden || op[i].hiderm || cla == 'hui' || cla == 'hidden' || cla == 'white')
			{
				if (op[i].rmtopborder && i < op.length - 1)
				{
					rmtopborder2 = true;
				}
				continue;
			}
			if (rmtopborder2)
			{
				op[i].rmtopborder = true;
				rmtopborder2 = false;
			}
			rm.push(op[i]);
		}
		rm.push({ // 查看本行详情
			fun : function()
			{
				var a = [];
				var haveTh = false;
				var arr = {};
				if (obj.tagName == 'TD')
					obj = obj.parentNode;
				for ( var k in ta.data)
				{
					if (ta.data[k]['data'] && ta.data[k]['data'][iu] !== undefined)
					{
						var h = ta.data[k]['header'];
						if (!h)
							h = k;
						var v = $(obj).find('td.td-' + k).html();
						if (!v)
							v = ta.data[k]['data'][iu];
						arr[k] = '<i class="hui">' + h + '</i> ' + v;
					}
				}
				$(obj).addClass('curhang curhang2');
				selectList(app.w('showThisRowDetail') + ' : ' + (index + 1), arr, null, 'detail copyenabled thisrowdetail', function()
				{
					$(obj).removeClass('curhang curhang2');
				});
			},
			icon : 'fa-money',
			rmtopborder : true,
			title : app.w('showThisRowDetail'),
		});
		rm.push({
			fun : function()
			{
				ta._explodeTd();
			},
			icon : 'fa-wpforms',
			title : app.w('explodeTd'),
		});
		for (var i = 0; i < rightMenu.length; i++)
		{
			if (!rightMenu[i].hidden)
				rm.push(rightMenu[i]);
		}
		var maxx = $(window).width();
		var maxy = $(window).height();
		var x = x0;
		var y = y0;
		if (!x && !y)
		{
			x = e.pageX;
			y = e.pageY;
		}
		if (!x && !y && e.touches && e.touches[0])
		{
			x = e.touches[0].pageX;
			y = e.touches[0].pageY;
		}
		x -= $(document).scrollLeft();
		y -= $(document).scrollTop();
		var w = 240;
		var h = (rm.length + 1) * (maxy > 600 ? 28 : 24) + 6;
		for (var ii = 0; ii < rm.length; ii++)
		{
			if (rm[ii]['rmtopborder'])
				h += 8;
		}
		if (h > maxy)
			h = maxy;
		if (x + w > maxx)
			x = x - w;
		if (y + h > maxy)
			y = y - h;
		if (x < 0)
			x = (maxx - w) / 2;
		if (y < 0)
		{
			y = (maxy - h) / 2;
		}
		var d = [];
		for ( var k in ta.data)
		{
			if (ta.data[k]['data'])
				d[k] = ta.data[k]['data'][index];
		}
		var idi = ta.data[ta.options.keyname].data[index];
		var t = '<div class="pointer gred" onclick="layer.close(tableFun.rightMenulayerIndex)" style="line-height:20px;text-align:center;position:absolute;right:4px;top:4px;width:20px;height:20px;border-radius:50%;">' + getIC('close white') + '</div>';
		t += '<ul style="margin-top:18px" class="rightmenu tablerightmenu" id="table' + ta.id + '">';
		for (var i = 0; i < rm.length; i++)
		{
			if (!rm[i].title)
				continue;
			var cl = '';
			if (rm[i].rmtopborder && i > 0)
				cl = 'class="topborderddd" ';
			t += '<li datai="' + i + '" ' + cl + '>' + getIC(rm[i].icon) + ' ' + rm[i].title + '</li>';
		}
		t += '</ul>';
		ta.rightMenuData = [ index, idi, d ];
		ta.rightMenuRm = rm;
		if (obj.tagName == 'TD')
			obj = obj.parentNode;
		$(obj).addClass('curhang curhang1');
		if (tableFun.rightMenulayerIndex)
			layer.close(tableFun.rightMenulayerIndex);
		tableFun.rightMenulayerIndex = layer.open({
			type : 1,
			title : false,
			offset : [ y, x ],
			shadeClose : !app.isIphone(),
			shade : 0.1,
			area : [ w + 'px', h + 'px' ],
			content : t,
			closeBtn : 0,
			skin : 'rightmenu',
			end : function()
			{
				$(obj).removeClass('curhang curhang1');
			}
		});
	}
	tableFun.prototype._setHeader = function()
	{
		var h = this.options.header;
		for ( var k in h)
		{
			if (!this.data)
				this.data = {};
			if (k == '_mu_' && h[k])
			{
				this.data[k] = h[k];
				continue;
			}
			if (k == '_op_')
			{
				if (h[k])
				{
					this.data[k] = h[k];
					this.opFuntionList = [];
					for ( var ic in this.data[k])
					{
						if (this.data[k][ic])
						{
							this.opFuntionList.push({
								fun : this.data[k][ic]['fun'],
								confirm : this.data[k][ic]['confirm'],
								muonce : this.data[k][ic]['muonce'],
							});
						}
					}
				}
				continue;
			}
			if (!this.options.keyname && k != '_mu_' && k != '_op_')
			{
				this.options.keyname = k;
			}
			var v = h[k];
			var datak = {};
			if (typeof v == 'string')
				datak['header'] = v;
			else if (v)
			{
				datak['header'] = v[0];
				if (v[1])
					datak['width'] = v[1];
				if (v[2])
					datak['type'] = v[2];
				if (v[3])
					datak['icon'] = v[3];
				if (v[4])
					datak['inputfun'] = v[4];
				if (v[5] && v[4])
					datak['dblclickedit'] = v[5];
				if (v[6])
					datak['getvaluefun'] = v[6];
				if (v[7])
					datak['clickfun'] = v[7];
			}
			datak['data'] = [];
			if (k == '_mu_' && !v)
				continue;
			this.data[k] = datak;
		}
		this._show();
	}
	/**
	 * 显示页标签
	 */
	tableFun.prototype._setPageHtml = function()
	{
		var okf = '';
		if (this.options.okFun)
		{
			if (!this.options._okFun)
			{
				if (!this.options.okFun[0])
				{
					this.options._okFun = [ {
						cap : app.w('ok'),
						fun : this.options.okFun
					} ];
				}
				else
				{
					this.options._okFun = this.options.okFun;
				}
			}
			for (var i = 0; i < this.options._okFun.length; i++)
			{
				// 各个按钮
				okf += '<li class="okfun" ><a page="' + (-1000 - i) + '"><button class="btn-info">' + this.options._okFun[i].cap + '</button></a></li>';
			}
		}
		if (!this.options.showpage)
		{
			if (okf)
				okf = '<ul class="pagination okfonly">' + okf + '</ul>';
			return okf;
		}
		var page = parseInt(this.page);
		if (page < 1)
			page = 1;
		var allpage = parseInt(this.allpage);
		if (!allpage)
			allpage = 1;
		if (!this.rows)
			this.rows = 0;
		if (allpage <= 1)
		{
			$('#' + this.id + ' .toppagestr').hide();
			$('#' + this.id + ' .bottompagestr').hide();
			$('#' + this.id + ' .pagestr').html('');
			return '';
		}
		$('#' + this.id + ' .toppagestr').show();
		$('#' + this.id + ' .bottompagestr').show();
		var sa = [];
		var a = [];
		var pre = page - 1;
		var nex = page + 1;
		if (nex > allpage)
			nex = 0;
		var t = '<ul class="pagination">';
		t += '<li class="paginate_button previous ' + (page == 1 ? 'disabled' : '') + '" >' + getIC('step-backward', 'a', 'page="' + pre + '"') + '</li>';
		a.push(1);
		var cp = 1;
		// 省略框
		if (page >= 5)
		{
			var p = Math.floor((page - 1) / 2);
			a.push(p);
			sa.push(p);
			for (var i = page - 2; i <= page + 2 && i <= allpage; i++)
			{
				a.push(i);
				cp = i;
			}
		}
		else
		{
			for (var i = 2; i <= page + 2 && i <= allpage; i++)
			{
				a.push(i);
				cp = i;
			}
		}
		if (allpage - cp > 1)
		{
			var p = Math.floor((allpage + cp) / 2);
			a.push(p);
			sa.push(p);
			cp = p;
		}
		if (allpage > cp)
		{
			a.push(allpage);
		}
		for (var i = 0; i < a.length; i++)
		{
			if (a[i] == sa[0] || a[i] == sa[1])
			{
				if (app.vm)
					continue;
				var ti = '...';
			}
			else
				var ti = a[i];
			t += '<li class="paginate_button ' + (a[i] == page ? 'active' : '') + '"><a page="' + a[i] + '">' + ti + '</a></li>';
		}
		t += '<li class="paginate_button next ' + (page == allpage ? 'disabled' : '') + '">' + getIC('step-forward', 'a', 'page="' + nex + '"') + '</li>';
		if (!app.vm && page < allpage)
			t += '<li class="paginate_button next">' + getIC('fast-forward', 'a', 'tryfindend="yes" page="' + (nex + 4) + '"') + '</li>';
		t += '<li class="paginate_button"><a page="-100">' + (this.morePageSize ? 'Fixed' : 'More') + '</a></li>';
		t += okf;
		t += '</ul>';
		$('#' + this.id + ' .pagestr').html(t);
		return t;
	}
	// 设置表体数据
	tableFun.prototype._setDataHtml = function(setdataing)
	{
		if (!this.data)
			return '';
		var t = '';
		if (!app.vm && this.morePageSize)
		{
			t += '<div class="row toppagestr"><div class="dataTables_paginate paging_simple_numbers pagestr"><!--pagestr--></div><i></i></div>';
		}
		if (this.options.listmodel == 'list')
			t += this._getListHtml();
		else
			t += this._getTableHtml();
		if (this.rows <= 0 && setdataing)
		{
			if (this.page <= 1 && this.options.noDataHtml)
				t += '<div class="no-data">' + this.options.noDataHtml + '</div>';
			else if (this.page <= 1)
				t += '<div class="no-data">' + app.w('login.msg.noData') + '</div>';
			else
				t += '<div class="no-data">' + app.w('login.msg.noDataInThisPage') + '</div>';
		}
		$('#' + this.id + ' #table').html(t);
		if (this.morePageSize > 0)
			$('#' + this.id + '.tablebox').addClass('morepage');
		else
			$('#' + this.id + '.tablebox').removeClass('morepage');
		return t;
	}
	/**
	 * 取得表体数据代码
	 */
	tableFun.prototype._getTableHtml = function()
	{
		this.mulist = {};
		var k = this.options.keyname;
		if (!(this.data[k]['data'] && this.data[k]['data'].length > 0))
		{
			return '';
		}
		var t = '';
		var tabeh = '<table class="table table-bordered dataTable ' + (!app.m && app.vm ? 'vm' : '') + '">';
		var hideopall = (this._isHideop() ? ' hideop ' : '');
		var dataRowsNumber = 0;
		var haveMu = false;
		for ( var k in this.data)
		{
			if (k == '_op_' || k == '_mu_' || (this.data[k] && this.data[k].header))
			{
				if (k == '_mu_')
				{
					if (this.data[k] && this.options.listmodel != 'list')
					{
						dataRowsNumber++;
						haveMu = true;
					}
				}
				else if (k != '_op_' || !this._isHideop())
					dataRowsNumber++;
			}
		}
		var icontd0 = this._isHideop() ? ' hideop ' : '';
		if (this.options.showheader)
		{
			// 表头
			t += '<thead><tr>';
			var dataRowsNumberi = 0;
			for ( var k in this.data)
			{
				var w = this.data[k].width ? (this.data[k].width + ' ').trim() : '';
				var icon = this.data[k].icon ? (' ' + this.data[k].icon) : '';
				if (w == '1%')
					icon += ' pre';
				if (dataRowsNumberi == dataRowsNumber - 1)
					icon += ' last-child';
				if (w)
				{
					w = (w + ' ').trim();
					if (w.indexOf('min') >= 0)
					{
						w = w.replace('min', '');
						w = ' style="min-width:' + w + '"';
					}
					else if (w.indexOf('max') >= 0)
					{
						w = w.replace('max', '');
						w = ' style="max-width:' + w + '";';
						if (!this.data[k].icon)
							this.data[k].icon = '';
						this.data[k].icon += ' pre ellipsis ';
					}
					else
					{
						icon += ' fixed';
						w = ' style="width:' + w + '"';
					}
				}
				if (k == '_mu_' && haveMu)
				{
					dataRowsNumberi++;
					t += '<th class="' + hideopall + icon + ' thtdmu th-_mu_"><input class="checks" type="checkbox"></th>';
				}
				else if (k == '_op_')
				{
					var hideoption = '';
					if (this.options.hideoption)
						hideoption = ' hidden';
					else
						dataRowsNumberi++;
					t += '<th class="thop' + icontd0 + icon + hideoption + '"></th>';
				}
				else if (k != '_mu_' && this.data[k] && this.data[k].header)
				{
					dataRowsNumberi++;
					t += '<th ' + w + ' class="' + icon + ' th-' + k + '">' + this.data[k].header + '</th>';
				}
			}
			t += '</tr></thead>';
		}
		var thHtml = t;
		t = tabeh + t;
		var pm = 0; // 多表显示
		// 全屏行数
		if (app.vm)
		{
			var maxpsat = $(window).height() / this.getTdHeight();
			if (this.rows > maxpsat * 2)
			{
				pm = Math.floor(this.rows / maxpsat);
				pm = Math.round(this.rows / pm);
			}
		}
		// 表体
		t += '<tbody>';
		// 以下为每行数据，值先赋予到ti
		for (var i = 0; i < this.rows; i++)
		{
			if (this.pagesize < i + 1)
				this.pagesize = i + 1;
			var ti = '';
			var p = this.page > 0 ? this.page : 1;
			var linei = (p - 1) * this.pagesize + i + 1;
			var cla = ' ';
			if (this.opclass && this.opclass[i] && this.opclass[i]['tr'])
			{
				cla = ' ' + this.opclass[i]['tr'];
			}
			if (this.options.clickTrFun)
				cla += ' a';
			if (!this.thisrowdetail)
				cla += ' longpress'
			ti += '<tr title="line : ' + linei + '" role="row" class="i' + i + ' odd ' + cla + '" i="' + i + '">';
			var dataRowsNumberi = 0;
			for ( var k in this.data)
			{
				var icontd = (dataRowsNumberi == dataRowsNumber - 1 ? ' last-child ' : '');
				if (k == '_mu_' && haveMu)
				{
					dataRowsNumberi++;
					ti += '<td class="thtdmu oddi' + icontd + ' td-_mu_" i="' + i + '" data-key="' + k + '">';
					if (this.data[this.options.keyname]['data'][i])
						ti += '<input class="check" i="' + i + '" type="checkbox">';
					ti += '</td>';
				}
				else if (k == '_op_')
				{
					var opclass = [];
					if (this.opclass)
						opclass = this.opclass[i] ? this.opclass[i] : [];
					hideopall = this.options.hideoption ? ' hidden' : '';
					if (!this.options.hideoption)
						dataRowsNumberi++;
					ti += '<td class="oddi' + hideopall + ' tdop ' + icontd + icontd0 + '" i="' + i + '" data-key="' + k + '">';
					for ( var ic in this.data[k])
					{
						if (!this.data[k][ic] || !this.data[k][ic]['icon'])
							continue;
						var title = this.data[k][ic]['title'] || '';
						var icon = this.data[k][ic]['icon'];
						if (!opclass[ic])
							opclass[ic] = '';
						if (this.data[k][ic]['hidden'])
						{
							if (this.data[k][ic]['hidden'] === true || this.data[k][ic]['hidden'] !== this.data[this.options.keyname]['data'][i])
								continue;
						}
						if (this.data[k][ic]['hideop'] === true || this.data[k][ic]['hiderm'] === true)
						{
							hideopclass = 'hideop';
							if (this.data[k][ic]['hiderm'] === true)
								hideopclass += ' hiderm';
						}
						else
							hideopclass = '';
						var cl = hideopclass + ' op ' + opclass[ic];
						var idd = 'op_' + i + '_' + ic;
						if (opclass[ic] != 'hui' && opclass[ic] != 'hidden')
						{
							this.mulist[ic] = true;
						}
						title = title.replace(/<[^>]+>/g, '');
						if (opclass[ic] == 'white')
						{
							icon = icon.replace('red', '').replace('yellow', '').replace('blue', '');
							ti += ' ' + getIC(icon + ' ' + cl, 'a', 'title=" "') + ' ';
						}
						else if (icon)
						{
							ti += ' ' + getIC(icon + ' ' + cl, 'a', 'id="' + idd + '" i="' + i + '" xi="' + ic + '" title="' + title + '"') + ' ';
						}
						else
						{
							ti += ' <a id="' + idd + '" i="' + i + '" xi="' + ic + '" class="' + cl + '" >' + title + '</a> ';
						}
					}
					ti += ' ' + getIC('ellipsis-v allright op', 'a') + ' ';
					ti += '</td>';
				}
				else if (k != '_mu_' && this.data[k] && this.data[k].header)
				{
					dataRowsNumberi++;
					var icon = this.data[k].icon || '';
					// 根据数据判断
					if (this.data[k].data.length > i)
					{
						var w = this.data[k].width;
						var type = this.data[k].type;
						if (type != 'date' && type != 'number')
							type = '';
						if (icon)
							icon = ' fa ' + icon;
						else
							icon = ' ';
						if (w == '1%')
							icon += ' pre ';
						w = w ? (w + ' ').trim() : '';
						if (w.indexOf('min') >= 0)
						{
							w = w.replace('min', '');
							w = ' style="min-width:' + w + '"';
						}
						else if (w.indexOf('max') >= 0)
						{
							w = w.replace('max', '');
							w = ' style="max-width:' + w + '";';
						}
						else if (w)
							w = 'style="width:' + w + '"';
						else
							w = '';
						var v = this.data[k].data[i];
						if (v === undefined)
							v = '';
						var dblclickeditCla = '';
						if (this.data[k].inputfun && !this.data[k].dblclickedit)
						{
							if (typeof v == 'string')
							{
								v = v.replace(/\"/g, "&quot;");
								v = v.replace(/\n/g, " ");
							}
							v = '<input type="' + type + '" value="' + v + '">';
							icon += ' input';
						}
						else
						{
							if (this.data[k].dblclickedit)
								dblclickeditCla = ' dblclickedit';
							if (w.indexOf('min') >= 0 || w.indexOf('max') >= 0 || w.indexOf('%') >= 0 || this.data[k].dblclickedit)
								var widthStyle = 'style="width:100%"';
							else if (w.indexOf('px') > 0)
								var widthStyle = w;
							else
								var widthStyle = '';
							v = '<span ' + widthStyle + (this.data[k].dblclickedit ? ' class="dblclickedit" ' : '') + '>' + v + '</span>';
						}
						ti += '<td class="oddi ' + icontd + ' td-' + k + icon + dblclickeditCla + (this.data[k].clickfun ? ' clickfun' : '') + '" i="' + i + '" ' + w + ' data-key="' + k + '">' + v + '</td>';
					}
					else
					{
						ti += '<td i="' + i + '" data-key="' + k + '" class="oddi ' + icontd + ' ' + icon + ' td-' + k + ' ' + (this.data[k].clickfun ? 'clickfun' : '') + '"></td>';
					}
				}
			}
			ti += '</tr>';
			t += ti;
			// 大于一定程度另起一个表头
			if (pm > 0 && i < this.rows - maxpsat / 2)
			{
				if (i % pm == pm - 1)
				{
					t += '</tbody>';
					t += thHtml;
				}
			}
		}
		t += '</tbody>';
		t += '</table>';
		var muHtml = this._getMuHtml();
		if (muHtml)
		{
			t += muHtml;
		}
		else
		{
			t = t.replace(/thtdmu/g, 'thtdmuhidden');
		}
		return t;
	}
	tableFun.prototype._getMuHtml = function()
	{
		var t = '';
		if (this.data['_mu_'] && this.options.listmodel != 'list')
		{
			var k = '_op_';
			var t0 = '';
			for ( var ic in this.data[k])
			{
				if (!this.mulist[ic])
					continue;
				var title = this.data[k][ic]['title'];
				var icon = this.data[k][ic]['icon'];
				if (this.data[k][ic]['_mu_'] === false)
					continue;
				if (this.data[k][ic]['hidden'])
				{
					if (this.data[k][ic]['hidden'] === true || this.data[k][ic]['hidden'] !== this.data[this.options.keyname]['data'][i])
						continue;
				}
				if (icon)
					t0 += ' ' + getIC(icon + ' mu', 'i', 'title="' + title + '" xi="' + ic + '"') + ' ';
				else
					t0 += ' <i xi="' + ic + '" class="mu" >' + title + '</i> ';
			}
			if (t0)
			{
				t += '<div class="selectmu" style="clear:both">';
				t += '<input class="checks" type="checkbox"> ';
				t += t0;
				t += '</div>';
			}
		}
		if (!app.vm && this.morePageSize && t && this.rows > this.fixedPageSize)
		{
			var that = this;
			setTimeout(function()
			{
				$('#' + that.id + ' .toppagestr i').html(t);
			}, 100);
		}
		return t;
	}
	/**
	 * 取得表体数据
	 */
	tableFun.prototype._getListHtml = function()
	{
		var t = '';
		for (var i = 0; i < this.rows; i++)
		{
			var cla = 'odd';
			if (!this.thisrowdetail)
				cla += ' longpress';
			t += '<ul role="row" class="' + cla + '" i="' + i + '" style="';
			if (this.options.listulwidth)
				t += 'width:' + this.options.listulwidth + 'px;';
			t += '">';
			for ( var k in this.data)
			{
				if (this.data[k].header && k != '_op_' && k != '_mu_')
				{
					if (this.data[k].data.length > i)
					{
						var icon = this.data[k].icon;
						if (icon)
							icon = 'fa ' + icon;
						else
							icon = '';
						var w = this.data[k].width;
						if (w)
							w = ' style="width:' + w + '" ';
						else
							w = '';
						t += '<li ' + w + ' class="oddi ' + icon + '" i="' + i + '" data-key="' + k + '">' + this.data[k].data[i] + '</li>';
					}
					else
					{
						t += '<li i="' + i + '" data-key="' + k + '" class="oddi"></li>';
					}
				}
			}
			t += '</ul>';
		}
		return t;
	}
	// 显示框架
	tableFun.prototype._show = function()
	{
		var that = this;
		if (!this.data)
			return;
		if ((this.options.classname + '').indexOf('thisrowdetail') >= 0)
			this.thisrowdetail = true;
		var container = this.options.container;
		var t = '';
		var cla = '';
		if (this.options.tophtml || this.options.refreshbtn)
			cla += ' classcmd';
		t += '<div class="box tablebox nav-tabs-custom ' + this.options.classname + cla + '" id="' + this.id + '" style="';
		if (this.options.height > 0)
			t += 'height:' + this.options.height + 'px;';
		if (container == 'maincontent' && !app.vm)
			t += 'min-height:' + app.getMainHeight() + 'px;';
		t += '">';
		if (this.options.tophelphtml)
		{
			t += '<div class="tip tophelphtml">' + this.options.tophelphtml + '</div>';
		}
		t += '<div class="box-body">';
		t += '<div class="dataTables_wrapper form-inline dt-bootstrap">';
		t += '<div class="row">';
		if (this._gettophtml())
		{
			if (this.options.caption)
				this.tophtml = '<span class="caption">' + this.options.caption + '</span>' + this.tophtml;
			t += '<div class="tophtml">' + this.tophtml + '</div>';
		}
		t += '<div class="col-sm-12" ' + (this.options.overflow ? (' style="overflow:' + this.options.overflow + '" ') : '') + ' id="table"><!--table--></div>';
		t += '</div>';
		// 页
		t += '<div class="row bottompagestr"><div class="dataTables_paginate paging_simple_numbers pagestr"><!--pagestr--></div></div>';
		t += '</div></div>';
		// 底部文件
		if (this.options.bottomhelphtml)
		{
			t += '<div class="tip bottomhelphtml">' + this.options.bottomhelphtml + '</div>';
		}
		t += '</div>';
		if (this.data)
		{
			t = t.replace('<!--table-->', this._setDataHtml());
			t = t.replace('<!--pagestr-->', this._setPageHtml());
		}
		if (container)
		{
			if (container == 'maincontent')
			{
				if (!app.vm)
					t += getIC('close righttopclose', 'span');
				left.setMainContentHtml(t, null, false, '', null, true);
			}
			else
				$('#' + container).html(t);
		}
		var that = this;
		setTimeout(function()
		{
			that.setData();
			if (that.cmdhtml)
				that.cmdhtml.showMoreLeft();
			if (app.vm)
				$('#' + that.id + ' ol.cmdbox').scrollLeft(320);
		}, 100);
		this.html = t;
	}
	tableFun.prototype._isHideop = function()
	{
		var hd = app.hideTableOption();
		if (this.options.hideop === true || this.options.hideop === false || this.options.hideop === 1 || this.options.hideop === 0)
			hd = this.options.hideop;
		return !!hd;
	}
	/**
	 * 取得顶部代码
	 */
	tableFun.prototype._gettophtml = function()
	{
		if (this.options.tophtml || this.options.refreshbtn || this.options.caption)
		{
			var that = this;
			if (!this.options.tophtml)
				this.options.tophtml = {};
			if (this.options.refreshbtn)
			{
				this.options.tophtml['_refresh'] = {
					caption : app.w('reset'),
					icon : 'fa-refresh',
					fun : function(fun)
					{
						that.resetTophtml();
						var havesearch = false;
						if (that.searchPara)
						{
							for ( var k in that.searchPara)
							{
								if (that.searchPara[k])
								{
									havesearch = true;
									break;
								}
							}
						}
						that.searchPara = null;
						if (havesearch)
						{
							that.setData(null, 1);
						}
						else
						{
							that.setData();
						}
						if (that.cmdhtml)
							that.cmdhtml.showMoreLeft();
					}
				};
			}
			this.cmdhtml = new cmdFun({
				classname : 'topcmd ',
				single : true,
				tableid : this.id,
				cmdlist : this.options.tophtml
			});
			this.tophtml = this.cmdhtml.html;
			return true;
		}
		else
			return false;
	}
	window.tableFun = tableFun;
}());
